package com.dy.design_pattern_study.memento_pattern.dome2;

import lombok.Data;

/**
 * @CreateBy zhangdingyi
 * @Date 2023-04-10
 * @Content 发起人类 -发起保存状态
 */
@Data
public class Originator {

    private String state;

    /**
     * 创建备忘录 -备份，把当前需要保存的信息导入并实例化
     * @return
     */
    public Memento createMemento(){
        return (new Memento(state));
    }

    /**
     * 恢复备忘录，并将 memento 导入的相关数据恢复
     * @param memento
     */
    public void setMemento(Memento memento){
        state = memento.getState();
    }

    public void show(){
        System.out.println("state = " + state);
    }


}
